package com.wdcloud.netlibrary.request;

import java.util.Map;

import okhttp3.FormBody;

/**
 * post请求
 * <p>
 */
public class PostRequest extends BaseRequest<PostRequest> {

    @Override
    public void buildRequest() {
        if (url == null) {
            throw new RuntimeException("请求路径不能为空");
        }

        FormBody.Builder bodyBuilder = new FormBody.Builder();
        if (params != null) {
            for (Map.Entry<String, String> entry : params.entrySet()) {
                if (null == entry.getValue()) {
                    bodyBuilder.add(entry.getKey(), "");
                } else {
                    bodyBuilder.add(entry.getKey(), entry.getValue());
                }
            }
        }
        builder.url(url).post(bodyBuilder.build());
    }
}
